const mongoose = require('mongoose');
const orderSchema = new mongoose.Schema({
    productId: { type: mongoose.Schema.Types.ObjectId, ref: 'Product' },
    quantity: { type: Number },
    total: { type: Number }, // 可计算字段
    orderTime: { type: Number }
});
// 添加复合索引，优化常用查询场景
// 添加复合索引，优化常用查询场景
orderSchema.index({ productId: 1, orderTime: -1 });
orderSchema.index({ total: -1 });
module.exports = mongoose.model('Order', orderSchema);
